package com.hui.wanxin.web.common.controller;

import com.hui.wanxin.web.common.service.CommonService;
import com.hui.wanxin.web.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Random;

/**
 * @author: 灰灰
 * @date: 2023年10月14日 12:25
 * @ClassName: CommonController
 * @Description: TODO
 */
@RestController
@RequestMapping("/web/common")
public class CommonController {

    @Autowired
    private CommonService commonService;


    @PostMapping("/upload")
    public String upload( @RequestParam("file")MultipartFile multipartFile){
        return commonService.upload(multipartFile);
    }

    @PostMapping("/sendCode/{phone}")
    public R sendCode(@PathVariable("phone")String phone){
        Random random = new Random();
        int code = random.nextInt(6);
        commonService.sendCode(phone,code);
        return R.success();
    }
    @GetMapping("/search/{content}")
    public R search(@PathVariable(value = "content")String content){

        return commonService.search(content);
    }

}
